package com.wnxy.admin.config;

/*
*  延迟队列配置类
*
* */

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DelayPluginsConfig {

    @Bean
    public CustomExchange delayPluginsExchange() {
        Map<String, Object> args = new HashMap<>();
//        设置交换机的类型
        args.put("x-delayed-type", "direct");
        return new CustomExchange(MessageQueueConfig.DELAY_SWITCH, "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue delayedPluginsQueue() {
        return new Queue(MessageQueueConfig.DELAY_QUEUE);
    }

    @Bean
    public Binding delayedPluginsBinding() {
        return BindingBuilder
                .bind(delayedPluginsQueue())
                .to(delayPluginsExchange())
                .with(MessageQueueConfig.ROUTING_KEY).noargs();
    }

    /**
     * @author lqc
     *预约延迟插件绑定
     * */
    @Bean
    public Binding delayedPluginsBindingReservation() {
        return BindingBuilder
                .bind(delayedPluginsQueueReservation())
                .to(delayPluginsExchange())
                .with(MessageQueueConfig.RES_ROUTING_KEY).noargs();
    }

    /**
     * @author lqc
     *预约延迟队列
     * */
    @Bean
    public Queue delayedPluginsQueueReservation() {
        return new Queue(MessageQueueConfig.RES_DELAY_QUEUE);
    }
}
